"""Initial

Revision ID: 5378e1eac5d3
Revises: 
Create Date: 2023-09-23 11:30:10.422099

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "5378e1eac5d3"
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "admin_user",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("email", sa.String(), nullable=False),
        sa.Column("password", sa.String(), nullable=False),
        sa.Column("name", sa.String(), nullable=False),
        sa.Column("can_create_admins", sa.Boolean(), server_default="0", nullable=False),
        sa.Column("can_export", sa.Boolean(), server_default="0", nullable=False),
        sa.Column("can_delete", sa.Boolean(), server_default="0", nullable=True),
        sa.Column("can_edit", sa.Boolean(), server_default="0", nullable=True),
        sa.Column("can_add", sa.Boolean(), server_default="0", nullable=True),
        sa.Column("can_view_files", sa.Boolean(), server_default="0", nullable=True),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_admin_user")),
        sa.UniqueConstraint("email", name=op.f("uq_admin_user_email")),
    )
    op.create_table(
        "category",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("title", sa.String(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_category")),
    )
    op.create_table(
        "delivery_zone",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("title", sa.String(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_delivery_zone")),
    )
    op.create_table(
        "discount",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("discount_type", sa.Enum("percent", name="discounttype"), nullable=False),
        sa.Column("discount_amount", sa.Integer(), nullable=False),
        sa.Column("required_quantity", sa.Float(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_discount")),
    )
    op.create_table(
        "feeling",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("title", sa.String(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_feeling")),
    )
    op.create_table(
        "genetics",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("title", sa.String(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_genetics")),
    )
    op.create_table(
        "payment_details",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column(
            "currency",
            sa.Enum("thb", "rub", "usdt", "btc", "ton", name="currency"),
            nullable=False,
        ),
        sa.Column(
            "currency_symbol",
            sa.Enum("thb", "rub", "usdt", name="currencysymbol"),
            server_default="thb",
            nullable=False,
        ),
        sa.Column("payment_address", sa.String(), nullable=False),
        sa.Column("exchange_rate", sa.Float(), server_default="0", nullable=True),
        sa.Column("exchange_percent", sa.Float(), nullable=True),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_payment_details")),
    )
    op.create_table(
        "stats",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("date", sa.DateTime(), server_default=sa.text("now()"), nullable=False),
        sa.Column("products_purchased", sa.Integer(), server_default="0", nullable=False),
        sa.Column("orders_created", sa.Integer(), server_default="0", nullable=False),
        sa.Column("users_registered", sa.Integer(), server_default="0", nullable=False),
        sa.Column("tickets_opened", sa.Integer(), server_default="0", nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_stats")),
        sa.UniqueConstraint("date", name=op.f("uq_stats_date")),
    )
    op.create_table(
        "product",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("title", sa.String(), nullable=False),
        sa.Column("image_path", sa.String(), nullable=False),
        sa.Column("description", sa.TEXT(), nullable=False),
        sa.Column("category_id", sa.Integer(), nullable=False),
        sa.Column("price", sa.Float(), nullable=False),
        sa.Column("weight", sa.Float(), server_default="1", nullable=False),
        sa.Column("sold_count", sa.Integer(), server_default="0", nullable=False),
        sa.Column("strain_name", sa.String(), nullable=True),
        sa.Column(
            "strain_type",
            sa.Enum(
                "indica",
                "sativa",
                "indica_dominant",
                "sativa_dominant",
                "hybrid",
                name="straintype",
            ),
            nullable=False,
        ),
        sa.Column("thc", sa.Integer(), nullable=True),
        sa.Column("origin", sa.String(), nullable=True),
        sa.Column("pgr", sa.Boolean(), server_default=sa.text("false"), nullable=False),
        sa.Column("vhq", sa.Boolean(), server_default=sa.text("true"), nullable=False),
        sa.Column("cbd", sa.String(), nullable=True),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.ForeignKeyConstraint(
            ["category_id"],
            ["category.id"],
            name=op.f("fk_product_category_id_category"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_product")),
    )
    op.create_table(
        "shop",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("title", sa.String(), nullable=False),
        sa.Column("delivery_zone_id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.ForeignKeyConstraint(
            ["delivery_zone_id"],
            ["delivery_zone.id"],
            name=op.f("fk_shop_delivery_zone_id_delivery_zone"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_shop")),
    )
    op.create_table(
        "product_feelings",
        sa.Column("product_id", sa.Integer(), nullable=True),
        sa.Column("feeling_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["feeling_id"],
            ["feeling.id"],
            name=op.f("fk_product_feelings_feeling_id_feeling"),
        ),
        sa.ForeignKeyConstraint(
            ["product_id"],
            ["product.id"],
            name=op.f("fk_product_feelings_product_id_product"),
        ),
    )
    op.create_table(
        "products_genetics",
        sa.Column("product_id", sa.Integer(), nullable=True),
        sa.Column("genetics_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(
            ["genetics_id"],
            ["genetics.id"],
            name=op.f("fk_products_genetics_genetics_id_genetics"),
        ),
        sa.ForeignKeyConstraint(
            ["product_id"],
            ["product.id"],
            name=op.f("fk_products_genetics_product_id_product"),
        ),
    )
    op.create_table(
        "stock",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("product_id", sa.Integer(), nullable=False),
        sa.Column("shop_id", sa.Integer(), nullable=False),
        sa.Column("available_quantity", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.ForeignKeyConstraint(["product_id"], ["product.id"], name=op.f("fk_stock_product_id_product")),
        sa.ForeignKeyConstraint(["shop_id"], ["shop.id"], name=op.f("fk_stock_shop_id_shop")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_stock")),
    )
    op.create_table(
        "user",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("telegram_id", sa.BigInteger(), nullable=False),
        sa.Column("username", sa.String(), nullable=False),
        sa.Column(
            "role",
            sa.Enum("user", "stuff", "admin", name="userrole"),
            server_default="user",
            nullable=False,
        ),
        sa.Column("is_adult", sa.Boolean(), server_default=sa.text("false"), nullable=False),
        sa.Column("address", sa.String(), nullable=True),
        sa.Column("phone", sa.String(), nullable=True),
        sa.Column("delivery_zone_id", sa.Integer(), nullable=True),
        sa.Column("shop_id", sa.Integer(), nullable=True),
        sa.Column(
            "lang_code",
            sa.Enum("ru", "en", name="langcode"),
            server_default="ru",
            nullable=False,
        ),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.ForeignKeyConstraint(
            ["delivery_zone_id"],
            ["delivery_zone.id"],
            name=op.f("fk_user_delivery_zone_id_delivery_zone"),
        ),
        sa.ForeignKeyConstraint(["shop_id"], ["shop.id"], name=op.f("fk_user_shop_id_shop")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_user")),
        sa.UniqueConstraint("telegram_id", name=op.f("uq_user_telegram_id")),
    )
    op.create_table(
        "cart",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.ForeignKeyConstraint(["user_id"], ["user.id"], name=op.f("fk_cart_user_id_user")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_cart")),
        sa.UniqueConstraint("user_id", name=op.f("uq_cart_user_id")),
    )
    op.create_table(
        "order",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column(
            "status",
            sa.Enum(
                "created",
                "payment_not_confirmed",
                "payment_confirmed",
                "collecting",
                "in_transit",
                "closed",
                "cancelled",
                "payment_canceled",
                "on_dispute",
                name="orderstatus",
            ),
            server_default="created",
            nullable=False,
        ),
        sa.Column("summ", sa.Float(), nullable=False),
        sa.Column("comment", sa.TEXT(), nullable=True),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("payment_method_id", sa.Integer(), nullable=True),
        sa.Column("shipping_address", sa.String(), nullable=True),
        sa.Column("user_phone", sa.String(), nullable=True),
        sa.Column("shop_id", sa.Integer(), nullable=False),
        sa.Column("tracking_link", sa.String(), nullable=True),
        sa.Column("invoice_screenshot_path", sa.String(), nullable=True),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.ForeignKeyConstraint(
            ["payment_method_id"],
            ["payment_details.id"],
            name=op.f("fk_order_payment_method_id_payment_details"),
        ),
        sa.ForeignKeyConstraint(["shop_id"], ["shop.id"], name=op.f("fk_order_shop_id_shop")),
        sa.ForeignKeyConstraint(["user_id"], ["user.id"], name=op.f("fk_order_user_id_user")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_order")),
    )
    op.create_table(
        "review",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("review_text", sa.TEXT(), nullable=False),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.ForeignKeyConstraint(["user_id"], ["user.id"], name=op.f("fk_review_user_id_user")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_review")),
    )
    op.create_table(
        "cart_product",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("product_id", sa.Integer(), nullable=False),
        sa.Column("cart_id", sa.Integer(), nullable=True),
        sa.Column("quantity", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.ForeignKeyConstraint(["cart_id"], ["cart.id"], name=op.f("fk_cart_product_cart_id_cart")),
        sa.ForeignKeyConstraint(
            ["product_id"],
            ["product.id"],
            name=op.f("fk_cart_product_product_id_product"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_cart_product")),
    )
    op.create_table(
        "order_line",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("order_id", sa.Integer(), nullable=False),
        sa.Column("product_id", sa.Integer(), nullable=False),
        sa.Column("quantity", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.ForeignKeyConstraint(
            ["order_id"],
            ["order.id"],
            name=op.f("fk_order_line_order_id_order"),
            ondelete="CASCADE",
        ),
        sa.ForeignKeyConstraint(
            ["product_id"],
            ["product.id"],
            name=op.f("fk_order_line_product_id_product"),
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_order_line")),
    )
    op.create_table(
        "orders_users",
        sa.Column("order_id", sa.Integer(), nullable=True),
        sa.Column("user_id", sa.Integer(), nullable=True),
        sa.ForeignKeyConstraint(["order_id"], ["order.id"], name=op.f("fk_orders_users_order_id_order")),
        sa.ForeignKeyConstraint(["user_id"], ["user.id"], name=op.f("fk_orders_users_user_id_user")),
    )
    op.create_table(
        "ticket",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column(
            "status",
            sa.Enum("opened", "closed", name="ticketstatus"),
            server_default="opened",
            nullable=False,
        ),
        sa.Column("admin_id", sa.Integer(), nullable=True),
        sa.Column("telegram_id", sa.BigInteger(), nullable=False),
        sa.Column("username", sa.String(), nullable=False),
        sa.Column("order_id", sa.Integer(), nullable=True),
        sa.Column("created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.Column("updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=True),
        sa.ForeignKeyConstraint(["admin_id"], ["user.id"], name=op.f("fk_ticket_admin_id_user")),
        sa.ForeignKeyConstraint(["order_id"], ["order.id"], name=op.f("fk_ticket_order_id_order")),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_ticket")),
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table("ticket")
    op.drop_table("orders_users")
    op.drop_table("order_line")
    op.drop_table("cart_product")
    op.drop_table("review")
    op.drop_table("order")
    op.drop_table("cart")
    op.drop_table("user")
    op.drop_table("stock")
    op.drop_table("products_genetics")
    op.drop_table("product_feelings")
    op.drop_table("shop")
    op.drop_table("product")
    op.drop_table("stats")
    op.drop_table("payment_details")
    op.drop_table("genetics")
    op.drop_table("feeling")
    op.drop_table("discount")
    op.drop_table("delivery_zone")
    op.drop_table("category")
    op.drop_table("admin_user")
    # ### end Alembic commands ###
